package com.zlsy.springbootdemo.chainofresponsibility.mtdemo2.rule;

import com.zlsy.springbootdemo.chainofresponsibility.mtdemo2.BasicRule;
import com.zlsy.springbootdemo.chainofresponsibility.mtdemo2.context.UserPortrait;
import com.zlsy.springbootdemo.chainofresponsibility.mtdemo2.context.UserPortraitRuleContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author zhouliang
 * @date 2021/1/23 15:09 【规则1：判断服务可用性】
 */
@Slf4j
@Component
public class ServiceAvailableRule extends BasicRule<UserPortrait, UserPortraitRuleContext> {
  @Override
  public boolean evaluate(UserPortraitRuleContext context) {
    UserPortraitRuleContext.TakeawayUserPortraitBasicInfo basicInfo = context.getBasicInfo();
    boolean serviceFail = basicInfo.isServiceFail();
    if (serviceFail) {
      log.info("服务不可用！");
      return false;
    }
    return true;
  }

  @Override
  public void execute(UserPortraitRuleContext context) {}
}
